#pragma once

#include "BaseEntity.h"
#include <string>
#include <iostream>
#include <list>
#include <math.h>
#include "EntityList.h"
#include "PhysicsManager.h"
#include "GameLogic.h"

class BaseFactory
{
public:
	virtual BaseEntity* Create(sf::RenderWindow *App) = 0;
};

template <class Entity_Type>
class EntityFactory : public BaseFactory
{
public:
	BaseEntity* Create(sf::RenderWindow *App) {return new Entity_Type(App);}
};

class EntityManager
{
private:
	sf::Clock CurTime;
	std::map<std::string, BaseFactory*> FactoryMap;

	EntityList *Entities;
	PhysicsManager *Physics;

	double LastFrame;
	double FrameTime;
	double CurrentTime;
    double Delta;
	double LastThink;
	int NewEntityID;
public:
	sf::RenderWindow *pRender;
	GameLogic *GameRules;
	static EntityManager* Instance();
	EntityManager(void);
	~EntityManager(void);

	void Init();
	void Tick();
	BaseEntity* CreateEntity(std::string ID);
	void RegisterEntity(std::string Name, BaseFactory *Factory);
	void FindByClass(std::string classname, std::vector<BaseEntity*> &vec);
};
